import FishSetting from "./FishSetting";
import FishManager from "../../script/game/manager/FishManager";
import CannonManager from "../../script/game/manager/CannonManager";
import SceneNavigator from "../../../base/Script/core/SceneNavigator";
import BundleUpdateModule from "../../../base/Script/module/BundleUpdateModule";
import MusicPrefab from "../../script/engine/uicomponent/MusicPrefab";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FishUI extends cc.Component {

    public static instance: FishUI = null;

    @property({type:cc.Label})
    private txtScore:cc.Label = null;

    @property({type:cc.Label})
    private labVersion:cc.Label = null;

    @property({type:cc.Animation})
    private clickEffect:cc.Animation = null;

    @property({type:cc.Node})
    private  waveEffect:cc.Node = null;

    public score:number = 1000000

    onLoad() {
        FishUI.instance = this;
        this.clickEffect.node.active = false;
        this.waveEffect.active = false;
        this.labVersion.string = BundleUpdateModule.ins().getBundleVersion('FishSingle');
    }

    start() {
        this.refreshScore();

        // setTimeout(()=>{
        //     this.playWaveEffect();
        // }, 5000)
    }

    public playClickEffect(p:cc.Vec2){
        this.clickEffect.node.setPosition(p);
        this.clickEffect.node.active = true;
        this.clickEffect.play();
    }

    public playWaveEffect(){
        this.waveEffect.active = true;
        this.waveEffect.setPosition(1292.703, 0)

        FishManager.instance.playFishMap();
        cc.tween(this.waveEffect).to(2, {position: cc.v3(-1319.969, 0, 0) }).call(() => {
           this.waveEffect.active = false;
           FishManager.instance.startFishMap()
        }).start()

    }

    private onClickPre() {
        if (CannonManager.instance.cannonType > 1) {
            CannonManager.instance.cannonType--;
            CannonManager.instance.refreshCannon()
        }
    }

    private onClickNext() {
        if (CannonManager.instance.cannonType < 7) {
            CannonManager.instance.cannonType++;
            CannonManager.instance.refreshCannon()
        }
    }
    
    public refreshScore(){
        this.txtScore.string = this.score+""
    }

    private onClickSetting(){
        FishSetting.show();
    }

    private onClickQuite(){
        SceneNavigator.goHome({});
    }

    onDestroy() {
        MusicPrefab.pause();
        FishUI.instance = null;
        this.unscheduleAllCallbacks();
        this.node.stopAllActions();
    }
}
